<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<link href="css/style.css" rel="stylesheet" type="text/css">
<link href="css/netinfo.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="js/libs/VatataKeyMove.js" ></script>
<script type="text/javascript" src="js/libs/VatataPublic.js" ></script>
<script type="text/javascript" src="js/libs/VatataStatue.js" ></script>
<script type="text/javascript">
var focusExe = false;
var pageIndex = 1;
var pageSize = 21;
var totalPage = 1;
var m_intent = null;
var m_manager = null;
var eventSender_obj = null;
var  xmlContent;
var focusI = 0;
var city_obj = null;
var  net_obj_time = null;
var apps_obj=null;
window.onWAEReady = function(waeObj){
	//VatataStatus.init();
	//eventListener();
	//console.log('--------get data---------');
	if (!city_obj) {
		city_obj = wae.create("Net.HttpClient");
	}
	if (!net_obj_time) {
		net_obj_time = wae.create("Net.HttpClient");
	}
	m_intent = wae.create("Intent");
	//alert('before create');
	apps_obj=wae.create("AppManager")
/*
	m_manager = wae.create("Market.OutsideInquirier");
	
	m_manager.onDatabaseChanged=function(e){
		getData();
		showVersion()
		bindDate();
	}
*/	
	getData();
	showVersion()
	bindDate();
	//VatataPublic.updatetime_Temperature($("weekId"),$("timeId"),$("temperatureId"),$("temperatureImgId"));
		
}
var eventListener_obj = null;
var code = false;
function eventListener(){
	eventListener_obj = wae.create("EventListener");
	eventListener_obj.onKeyEvent = function (e){
		var key =  e.arguments[0].toLocaleString() ;   //URL
		code = true;
		getData();
		bindDate();
   }

	eventListener_obj.add('82') ;
}
function getData(){
		xmlContent =	apps_obj.getInstalledApps()//allapps
		//xmlContent = m_manager.getAllInstalledApps();
}

function bindDate(){
    //alert("游戏:"+xmlContent);
    if (xmlContent) {
        var xmlObj = (new DOMParser()).parseFromString(xmlContent, "application/xhtml+xml");
        var _xml_apps = xmlObj.getElementsByTagName("appdata");
        if (_xml_apps.length > 0) {
			//alert("_xml_apps.length:"+_xml_apps.length);
			var i = (pageIndex - 1) * pageSize;
			focusI = i;
			//alert("i:"+i);
			var j = _xml_apps.length-i > pageSize ? parseInt(pageSize+i) : _xml_apps.length;
			//alert("j:"+j);
			totalPage = Math.ceil(_xml_apps.length / pageSize);
			//alert("totalPage:"+totalPage);
			var htmlStr = "";
            for (i; i < j; i++) {
            	console.log("bindDate : " + i + " : " +  _xml_apps[i].getAttribute("apk_name")  );
                if ( _xml_apps[i].getAttribute("apk_name") == "com.tvata.smartv.ktv" ) {                	
                    continue;
                }
				htmlStr+='	    	<a id="a'+i+'" href="javascript:;" onclick="openPackage(\''+_xml_apps[i].getAttribute("apk_name")+'\');" class="left" onfocus="VatataPublic.startRoll(this.children[1])" onblur="VatataPublic.stopRoll(this.children[1])">';
				htmlStr+='			<img src="'+_xml_apps[i].getAttribute("ico")+'"   onerror="this.src=\'images/android_default_icon.png\'"  />	';
				htmlStr+='			<div class="gund">'+_xml_apps[i].firstChild.nodeValue+'</div>'
				htmlStr+='			</a>';
            }
            document.getElementById("dataList").innerHTML = htmlStr;
            pagerInit();
			VatataKeyMove.initVttKeymoveById($("a"+focusI));
        }
    }
}

function openPackage(pkgName){
     m_intent.startActivity(pkgName);    
     if ( pkgName == "com.android.chrome" ) {
     	console.log("start chrome, try stop app!");
     	var app = wae.create("Application");
     	app.finishActivity();
     }
}


function pagerInit(){
		document.getElementById("pageIndex").innerText = pageIndex;
		document.getElementById("totalPage").innerText = totalPage;
}

function pageUp(){
	//alert('pageDown:'+totalPage+',pageIndex:'+pageIndex);
	if( pageIndex > 1){
		pageIndex--;
		bindDate();
		pagerInit();
	}else{
		var _prevEle = VatataKeyMove.getPrevEle();//上一个id
//		var _currEle = VatataKeyMove.getCurrentEle(); 当前id
		VatataKeyMove.initVttKeymoveById(_prevEle);
	}
}

function pageDown(){
	//alert('pageDown:'+totalPage+',pageIndex:'+pageIndex);
	if( pageIndex < totalPage){
		pageIndex++;
		bindDate();
		pagerInit();
	}else{
		var _prevEle = VatataKeyMove.getPrevEle();//上一个id
//		var _currEle = VatataKeyMove.getCurrentEle(); 当前id
		VatataKeyMove.initVttKeymoveById(_prevEle);
	}
}

/**
 * 显示版本号
 */
var HTML_PAGE_VERSION = "19";
var application_obj = null;
function showVersion(){
	if(!application_obj){
		application_obj = wae.create("Application");
	}
	document.getElementById('versionName').innerText = 'V '+application_obj.versionName() + '.' + HTML_PAGE_VERSION;
}
</script>
</head>

<body>
<div class="container">
	<div class="header_erji">
    <div class="angle"></div>
  <div class="title fl">
            <img src="images/arrowbotm.png">
            Local Apps
        </div>
        <!--<div class="now fr">
            <div class="date1 fl" id="dateLabel" ></div>
            <div class="time1 fl" id="timeLabel" ></div>
            <div class="clear"></div>
        </div>-->
        
      <div class="now fr nows">
       <!--网络状态开始-->
           <!--<div class="netinfo">
                <div class="logos">
                    <img src="images/publicinfo/wifi_0.png"  id="netTypeImgId"/>
                    <img src="images/publicinfo/remoter_off.png" id="remoteControlImgId" style="display:none"/>
                    <img src="images/publicinfo/tvata_server_off.png" id="tvataStatusImgId" />
                </div>
                <div class="device"><span id="deviceNameId" style="float:left;color: #FFFFFF"></span></div>
            </div>-->
         <!--网络状态结束-->
         
         <!--天气状态开始-->
         	
            <div class="now fr">
                <img onerror="this.src='images/default.png'" style="display:none;" class="fl" id="temperatureImgId">
                <div class="week fl" id="weekId" style="display:none;"></div>
                <div class="date1 fl">
                    <span id="timeId" class="time2" style="display:none;"></span>
                    <span class="time1" id="temperatureId" style="display:none;"></span>
                </div>
                <div class="degrees fl"></div>
                
                <div class="clear"></div>
            </div>
         <!--天气状态结束-->
         
<!--             <iframe src="" id="weather" frameborder="0" scrolling="no" class="iframe_inte "></iframe>
             <iframe src="" id="inte" frameborder="0" scrolling="no" class="iframe_weather"></iframe> -->
        </div>
    </div>
    
<div class="main">
       
        <div class="mainRgt">
        	<div class="hoverbar"><a href="javascript:pageDown()" onfocus="pageUp()"></a></div>
            	<ul class="video infor" id="dataList">
         <!--        <a href="#"  class="left">
                     <img src="images/default.png"/>
                     <div class="gund">非诚勿扰</div>
               	</a> 
                 
                 <a href="#"  class="left">
                     <img src="images/default.png"/>
                     <div class="gund">非诚勿扰</div>
               	</a> 
                
                	<li class="left">
                	<a href="#"><img /></a>
               		<div class="gund" ><span>asdfasdfds</span><span></span></div>
                    </li>
                    
                	
                    </li>
                    <li class="left">
                	<a href="#"><img /></a>
               		<div class="gund" ><span></span><span></span></div>
                    </li>-->
                   
                    <li class="clear"></li>
                </ul>
                <div class="pager pagersea">
           	    	<!--<div class="left"><span href="#" class="prePage"></span></div>-->
                    <div class="left">
                    	<span id="pageIndex">1</span>
                        <span>/</span>
                        <span id="totalPage">1</span>
                    </div>
                   <!--<div class="left"><span href="#" class="nextPage"></span></div>-->
                    <div class="clear"></div>
                </div>
                <div class="hoverbtnbar"><a href="javascript:pageDown()" onfocus="pageDown()"></a></div>
            </div>
        
    </div>
    
    <div class="numer" id="versionName"></div> 
</div>

<script>
		function $(str) { return document.getElementById(str)}
</script>


</body>
</html>
